<?php
class conexionBD
{
    private $host;
    private $usuario;
    private $pass;
    private $basedatos;
    private $conn;
    private $res;
    private $arr;
    
    public function __construct()
	{
        $this->host = 'localhost';
        $this->usuario = 'tuminita_mv1';
        $this->pass = 'grandfunk';
        $this->basedatos = 'tuminita_trunk';
		
		$this->arr = array();
		
		$this->conn = mysql_connect($this->host, $this->usuario,$this->pass);
		mysql_select_db($this->basedatos, $this->conn) OR DIE ("Error: Imposible Conectar");
    }
    public function obtener_conexion(){ return $this->conn; }
	public function cerrar_conexion(){ mysql_close(); }
	public function ejecutarSqlArray($sql)
	{
		mysql_query("SET NAMES 'utf8'");
		$this->res = mysql_query($sql) or die('Error SQL: '.mysql_error());
		$n = mysql_num_rows($this->res);
		
		if($n > 0)
		{
			$k=0;
			while($row = mysql_fetch_row($this->res))
			{
				$this->arr[$k] = $row;
				$k++;
			}
		}
		else $this->arr = null;
		
		return $this->arr;
	}
	public function numRows(){ return mysql_num_rows($this->res); }
	public function numCols()
	{
		$col = mysql_num_fields($this->res);
		return $col;
	}
	public function ejecutarSqlCruda($sql)
	{
		mysql_query("SET NAMES 'utf8'");
		mysql_query($sql, $this->conn);
			
		//Comprobaremos que todo ha ido correctamente
		$my_error = mysql_error($this->conn);
		
		if($my_error!='') return $my_error;
		else return 1;
	}
}
?>